//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.telecomyt.jwportal.widget;

import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorFilter;
import android.graphics.Paint;
import android.graphics.Paint.Align;
import android.graphics.Paint.Style;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.OvalShape;
import android.graphics.drawable.shapes.RectShape;
import android.graphics.drawable.shapes.RoundRectShape;

public class TextDrawable extends ShapeDrawable {
    private final Paint mTextPaint;
    private final Paint mBorderPaint;
    private static final float SHADE_FACTOR = 0.9F;
    private final String mText;
    private final int mColor;
    private final RectShape mShape;
    private final int mHeight;
    private final int mWidth;
    private final int mFontSize;
    private final float mRadius;
    private final int mBorderThickness;

    public TextDrawable(Paint var1, Paint var2, String var3, int var4, RectShape var5, int var6, int var7, int var8, float var9, int var10) {
        super(var5);
        this.mShape = var5;
        this.mHeight = var6;
        this.mWidth = var7;
        this.mRadius = var9;
        this.mText = var3;
        this.mColor = var4;
        this.mFontSize = var8;
        this.mTextPaint = new Paint();
        this.mTextPaint.setColor(var1.getColor());
        this.mTextPaint.setAntiAlias(true);
        this.mTextPaint.setFakeBoldText(var1.isFakeBoldText());
        this.mTextPaint.setStyle(var1.getStyle());
        this.mTextPaint.setTypeface(var1.getTypeface());
        this.mTextPaint.setTextAlign(var1.getTextAlign());
        this.mTextPaint.setStrokeWidth(var1.getStrokeWidth());
        this.mBorderThickness = var10;
        this.mBorderPaint = new Paint();
        this.mBorderPaint.setColor(var2.getColor());
        this.mBorderPaint.setStyle(var2.getStyle());
        this.mBorderPaint.setStrokeWidth(var2.getStrokeWidth());
        Paint var11 = this.getPaint();
        var11.setColor(this.mColor);
    }

    private TextDrawable(Builder var1) {
        super(var1.shape);
        this.mShape = var1.shape;
        this.mHeight = var1.height;
        this.mWidth = var1.width;
        this.mRadius = var1.radius;
        this.mText = var1.toUpperCase ? var1.text.toUpperCase() : var1.text;
        this.mColor = var1.color;
        this.mFontSize = var1.fontSize;
        this.mTextPaint = new Paint();
        this.mTextPaint.setColor(var1.textColor);
        this.mTextPaint.setAntiAlias(true);
        this.mTextPaint.setFakeBoldText(var1.isBold);
        this.mTextPaint.setStyle(Style.FILL);
        this.mTextPaint.setTypeface(var1.font);
        this.mTextPaint.setTextAlign(Align.CENTER);
        this.mTextPaint.setStrokeWidth((float)var1.borderThickness);
        this.mBorderThickness = var1.borderThickness;
        this.mBorderPaint = new Paint();
        this.mBorderPaint.setColor(this.getDarkerShade(this.mColor));
        this.mBorderPaint.setStyle(Style.STROKE);
        this.mBorderPaint.setStrokeWidth((float)this.mBorderThickness);
        Paint var2 = this.getPaint();
        var2.setColor(this.mColor);
    }

    private int getDarkerShade(int var1) {
        return Color.rgb((int)(0.9F * (float)Color.red(var1)), (int)(0.9F * (float)Color.green(var1)), (int)(0.9F * (float)Color.blue(var1)));
    }

    public void draw(Canvas var1) {
        super.draw(var1);
        Rect var2 = this.getBounds();
        if (this.mBorderThickness > 0) {
            this.drawBorder(var1);
        }

        int var3 = var1.save();
        var1.translate((float)var2.left, (float)var2.top);
        int var4 = this.mWidth < 0 ? var2.width() : this.mWidth;
        int var5 = this.mHeight < 0 ? var2.height() : this.mHeight;
        int var6 = this.mFontSize < 0 ? Math.min(var4, var5) / 2 : this.mFontSize;
        this.mTextPaint.setTextSize((float)var6);
        var1.drawText(this.mText, (float)(var4 / 2), (float)(var5 / 2) - (this.mTextPaint.descent() + this.mTextPaint.ascent()) / 2.0F, this.mTextPaint);
        var1.restoreToCount(var3);
    }

    private void drawBorder(Canvas var1) {
        RectF var2 = new RectF(this.getBounds());
        var2.inset((float)(this.mBorderThickness / 2), (float)(this.mBorderThickness / 2));
        if (this.mShape instanceof OvalShape) {
            var1.drawOval(var2, this.mBorderPaint);
        } else if (this.mShape instanceof RoundRectShape) {
            var1.drawRoundRect(var2, this.mRadius, this.mRadius, this.mBorderPaint);
        } else {
            var1.drawRect(var2, this.mBorderPaint);
        }

    }

    public void setAlpha(int var1) {
        this.mTextPaint.setAlpha(var1);
    }

    public void setColorFilter(ColorFilter var1) {
        this.mTextPaint.setColorFilter(var1);
    }

    public int getOpacity() {
        return -3;
    }

    public int getIntrinsicWidth() {
        return this.mWidth;
    }

    public int getIntrinsicHeight() {
        return this.mHeight;
    }

    public ConstantState getConstantState() {
        ConstantState var1 = super.getConstantState();
        return new TextState(var1, this);
    }

    public static IShapeBuilder builder() {
        return new Builder();
    }

    public interface IShapeBuilder {
        IConfigBuilder beginConfig();

        IBuilder rect();

        IBuilder round();

        IBuilder roundRect(int var1);

        TextDrawable buildRect(String var1, int var2);

        TextDrawable buildRoundRect(String var1, int var2, int var3);

        TextDrawable buildRound(String var1, int var2);
    }

    public interface IBuilder {
        TextDrawable build(String var1, int var2);
    }

    public interface IConfigBuilder {
        IConfigBuilder width(int var1);

        IConfigBuilder height(int var1);

        IConfigBuilder textColor(int var1);

        IConfigBuilder withBorder(int var1);

        IConfigBuilder useFont(Typeface var1);

        IConfigBuilder fontSize(int var1);

        IConfigBuilder bold();

        IConfigBuilder toUpperCase();

        IShapeBuilder endConfig();
    }

    public static class Builder implements IBuilder, IConfigBuilder, IShapeBuilder {
        private String text;
        private int color;
        private int borderThickness;
        private int width;
        private int height;
        private Typeface font;
        private RectShape shape;
        public int textColor;
        private int fontSize;
        private boolean isBold;
        private boolean toUpperCase;
        public float radius;

        private Builder() {
            this.text = "";
            this.color = -7829368;
            this.textColor = -1;
            this.borderThickness = 0;
            this.width = -1;
            this.height = -1;
            this.shape = new RectShape();
            this.font = Typeface.create("sans-serif-light", 0);
            this.fontSize = -1;
            this.isBold = false;
            this.toUpperCase = false;
        }

        public IConfigBuilder width(int var1) {
            this.width = var1;
            return this;
        }

        public IConfigBuilder height(int var1) {
            this.height = var1;
            return this;
        }

        public IConfigBuilder textColor(int var1) {
            this.textColor = var1;
            return this;
        }

        public IConfigBuilder withBorder(int var1) {
            this.borderThickness = var1;
            return this;
        }

        public IConfigBuilder useFont(Typeface var1) {
            this.font = var1;
            return this;
        }

        public IConfigBuilder fontSize(int var1) {
            this.fontSize = var1;
            return this;
        }

        public IConfigBuilder bold() {
            this.isBold = true;
            return this;
        }

        public IConfigBuilder toUpperCase() {
            this.toUpperCase = true;
            return this;
        }

        public IConfigBuilder beginConfig() {
            return this;
        }

        public IShapeBuilder endConfig() {
            return this;
        }

        public IBuilder rect() {
            this.shape = new RectShape();
            return this;
        }

        public IBuilder round() {
            this.shape = new OvalShape();
            return this;
        }

        public IBuilder roundRect(int var1) {
            this.radius = (float)var1;
            float[] var2 = new float[]{(float)var1, (float)var1, (float)var1, (float)var1, (float)var1, (float)var1, (float)var1, (float)var1};
            this.shape = new RoundRectShape(var2, (RectF)null, (float[])null);
            return this;
        }

        public TextDrawable buildRect(String var1, int var2) {
            this.rect();
            return this.build(var1, var2);
        }

        public TextDrawable buildRoundRect(String var1, int var2, int var3) {
            this.roundRect(var3);
            return this.build(var1, var2);
        }

        public TextDrawable buildRound(String var1, int var2) {
            this.round();
            return this.build(var1, var2);
        }

        public TextDrawable build(String var1, int var2) {
            this.color = var2;
            this.text = var1;
            return new TextDrawable(this);
        }
    }

    static final class TextState extends ConstantState {
        private TextDrawable mOwner;
        private ConstantState mOrigSt;

        public TextState(ConstantState var1, TextDrawable var2) {
            this.mOrigSt = var1;
            this.mOwner = var2;
        }

        public Drawable newDrawable() {
            return new TextDrawable((Builder)null);
        }

        public Drawable newDrawable(Resources var1) {
            return new TextDrawable(this.mOwner.mTextPaint, this.mOwner.mBorderPaint, this.mOwner.mText, this.mOwner.mColor, this.mOwner.mShape, this.mOwner.mHeight, this.mOwner.mWidth, this.mOwner.mFontSize, this.mOwner.mRadius, this.mOwner.mBorderThickness);
        }

        public int getChangingConfigurations() {
            return this.mOrigSt.getChangingConfigurations();
        }
    }
}
